/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.action;

import cms.util.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import dto.Conference;
import dto.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

/**
 *
 * @author Gary
 */
public class HomeAction extends ActionSupport{
    private HttpSession session;
    private HttpServletRequest request;
    public HomeAction() {
    }
     private static final long serialVersionUID = 7182215130854270652L;
     private List<Conference> conferences;
     private String conferenceName;
     private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
     private String password;

    public String getConferenceName() {
        return conferenceName;
    }

    public void setConferenceName(String conferenceName) {
        this.conferenceName = conferenceName;
    }

    public List<Conference> getConferences() {
        return conferences;
    }

    public void setConferences(List<Conference> conferences) {
        this.conferences = conferences;
    }
   
    public String list() throws Exception {
        conferences = new ArrayList<Conference>();
                for(int i = 0; i < 10; i++){
                    Conference dc = new Conference("AvailableConference" + i, "Siminar", "Sands Hotel", true, null, true, 99.90 + i*100,128);
                    boolean add = conferences.add(dc);
                }
        return "listconference";
    }
    public String toLogin(){
        return "userlogin";
    } 
    public String toRegister(){
        return "userregister";
    }
    public String participate(){
        if (conferenceName.trim().length() > 0) {
            ActionContext.getContext().getSession().put("ParticipateConference" , conferenceName); 
        }
        return "userlogin";
    }
    public String login()
    {
        User user = new User("admin", "admin", "member");
        if(username.equalsIgnoreCase(user.getUserName()) && password.equalsIgnoreCase(user.getPassword())){
            ActionContext.getContext().getSession().put("CurrentUser" , user); 
            conferenceName = ActionContext.getContext().getSession().get("ParticipateConference")==null ? null : ActionContext.getContext().getSession().get("ParticipateConference").toString();
            if (conferenceName != null) {
                return "participate";
            }
            return "logedin";
        } else {
          addFieldError("login", "Invalid User.");   
        return "userlogin";
        }
    }
}
